package com.bungarus.cluster;

import java.io.Serializable;
import java.util.Map;

/**
 * Created by tang on 2018/11/15.
 */
public class NodeInfo implements Serializable{
    public static final String SEPARATOR = ":";
    public static final String TAG_PORT_SEPARATOR = "|";
    public static final int HIGH_PERFORMANCE = 2;
    public static final int NORMAL_PERFORMANCE = 1;
    /**
     * cluster info the node belongs to
     */
    private String clusterBelongsTo;
    /**
     * cluster id the node belongs to, default is 1
     */
    private int clusterIDBelongsTo = 1;
    /**
     * access node id, default is 1
     */
    private int nodeId = 1;
    /**
     * node ip address
     */
    private String ip;
    /**
     * ports for receiving and sending messages
     */
    private Map<String, Integer> messagePorts;
    /**
     * communication protocol node supports
     * 0: tcp, 1: long polling, 2: both
     */
    private int protocol;
    /**
     * node status
     * 0: initializing
     * 1: running
     * 2: stop
     */
    private int status;

    /**
     * it is high performance or not
     */
    private boolean highPerformance = false;

    /**
     * extra information
     */
    private String extraInfo;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof NodeInfo)) return false;

        NodeInfo nodeInfo = (NodeInfo) o;

        return getNodeId() == nodeInfo.getNodeId();

    }

    @Override
    public String toString() {
        return "NodeInfo{" +
                "clusterBelongsTo='" + clusterBelongsTo + '\'' +
                ", clusterIDBelongsTo=" + clusterIDBelongsTo +
                ", nodeId=" + nodeId +
                ", status=" + status +
                ", ip='" + ip + '\'' +
                ", protocol=" + protocol +
                ", high performance=" + highPerformance +
                ", extraInfo=" + extraInfo +
                '}';
    }

    @Override
    public int hashCode() {
        return getNodeId();
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getProtocol() {
        return protocol;
    }

    public void setProtocol(int protocol) {
        this.protocol = protocol;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public void setClusterBelongsTo(String clusterBelongsTo) {
        this.clusterBelongsTo = clusterBelongsTo;
    }

    public void setClusterIDBelongsTo(int clusterIDBelongsTo) {
        this.clusterIDBelongsTo = clusterIDBelongsTo;
    }

    public int getNodeId() {
        return nodeId;
    }

    public void setNodeId(int nodeId) {
        this.nodeId = nodeId;
    }

    public String getClusterBelongsTo() {
        return clusterBelongsTo;
    }

    public int getClusterIDBelongsTo() {
        return clusterIDBelongsTo;
    }

    public Map<String, Integer> getMessagePorts() {
        return messagePorts;
    }

    public void setMessagePorts(Map<String, Integer> messagePorts) {
        this.messagePorts = messagePorts;
    }

    public boolean isHighPerformance() {
        return highPerformance;
    }

    public void setHighPerformance(boolean highPerformance) {
        this.highPerformance = highPerformance;
    }

    public String getExtraInfo() {
        return extraInfo;
    }

    public void setExtraInfo(String extraInfo) {
        this.extraInfo = extraInfo;
    }
}
